<template>
	<view class="agrotechny">
		<view class="back">
			<image class="back-img" @click="back" src="../../static/index/fanhui.png" mode=""></image>
			<text class="back-name">助力实体</text>
			<view class="search">
				<input class="search-input" placeholder-style="color:#fff" type="text" value="" placeholder="百事可乐" />
				<image class="search-img" src="../../static/index/search.png" mode=""></image>
			</view>
		</view>
		<view class="banner">
			<u-swiper height="334" :list="list1" @click="click"></u-swiper>
		</view>
		<ms-tabs :list="list" @input="tabsClick" @input2="ccc" v-model="active" :lineAnimated="true"></ms-tabs>
		<!-- <view class="shop-box" v-if="currentTabIndex==0"> -->
		<view class="shop-box">
			<view class="shop" v-for="(item,index) in shopList" :key="index">
				<image class="shop-img" :src="item.image" mode=""></image>
				<view class="shop-title">
					{{item.name}}
				</view>
				<view class="integral">
					<text>{{item.price}}积分</text>
					<text style="margin-left: 10rpx;">已兑换<text style="color: #000000;">{{item.sales}}</text>件</text>
				</view>
				<view class="price">
					原价：<text>￥{{item.original_price}}</text>
				</view>
				<view class="bottom">
					<view class="bottom-left">
						<image style="width: 30rpx;height: 28rpx;" src="../../static/earn/shopCar.png" mode=""></image>
					</view>
					<view class="bottom-right">
						立即兑换
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {getBanner} from '@/service/banner.js'//banner
	import {getspecialDoodsList,getSpecialType} from '@/service/goods.js'//专区商品列表--农特优选--地区  专区分类
	export default {
		components: {},
		data() {
			return {
				currentTabIndex: 0,
				shopList:[],//商品列表
				list: [],
				active: 0,
				params:{
					type:'',//商品分类id
					cls:'',
					limit:20,
					page:1
				},
				totalPage:0,//总页数
				list1:[],//轮播列表
			}
		},
		watch: {
			active() {
				// console.log(this.active,'101010') // 0
			}
		},
		onLoad(options) {
			this.params.cls = JSON.parse(options.cls);
			this.getSpecialType();
			this.getBanner();
		},
		methods: {
			//获取专区分类列表
			getSpecialType(){
				let params={
					type:1
				}
				getSpecialType(params).then(res=>{
					this.list = res.data
					this.params.type = res.data[0].id
					this.getspecialDoodsList();
				})
			},
			tabsClick(i) {
				this.currentTabIndex = i
			},
			ccc(item){
				this.shopList = []
				this.params.type = item.id
				this.getspecialDoodsList()
			},
			// 返回
			back() {
				uni.navigateBack()
			},
			//获取分类商品列表
			getspecialDoodsList(isMore){
				getspecialDoodsList(this.params).then(res=>{
					if(res.code=='200'){
						const list = res.data.data
						const total = res.data.total
						if(list.length===0){
							uni.showToast({ title: '暂无内容', icon: 'none' })
							return false
						}
						this.totalPage = Math.ceil(Number(total) / 20)
						this.shopList = isMore ? this.shopList.concat(list) : list
					}else{
						 uni.showToast({ title: res.msg || '获取列表失败', icon: 'none' })
					}
					
				})
			},
			//加载获取更多
			more() {
				if (this.params.page >= this.totalPage) {
					uni.showToast({ title: '没有更多啦~', icon: 'none' })
					return false
				}
				this.params.page++
				this.getspecialDoodsList(true)
			},
			//获取banner、
			getBanner(){
				let params = {
					type:4
				}
				getBanner(params).then(res=>{
					console.log(res,'广告部分');
					this.list1 = res.data
				})
			}

		}
	}
</script>

<style lang="less" scoped>
	/deep/.u-swiper-wrap{
		border-radius: 0 !important;
	}
	.shop-box{
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		margin-top: 34rpx;
		padding: 0 30rpx;
	}
	.shop {
		// padding: 10rpx;
		margin-bottom: 34rpx;
		width: 45%;
		height: 544rpx;
		background: #FFFFFF;
		box-shadow: 0px 4rpx 8rpx rgba(0, 0, 0, 0.16);
		border-radius: 10rpx;
		display: flex;
		flex-direction: column;

		.shop-img {
			margin: 10rpx 8rpx 24rpx 8rpx;
			width: 92%;   
			height: 310rpx;
			background: #FFFFFF;
			border: 1px solid #707070;
			border-radius: 5px;
		}

		.shop-title {
			padding-left: 22rpx;
			font-size: 20rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #333333;     
			margin-bottom: 15rpx;
		}

		.integral {
			padding-left: 22rpx;
			margin-bottom: 15rpx;

			text:first-child {
				font-size: 26rpx;
				font-family: Source Han Sans CN;
				font-weight: bold;
				color: #000000;
			}

			text:last-child {
				font-size: 20rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #999999;
			}
		}

		.price {
			padding-left: 22rpx;
			font-size: 22rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #FF7B7B;
			margin-bottom: 15rpx;

			text {
				text-decoration: line-through;
				font-size: 20rpx;
			}
		}

		.bottom {
			display: flex;

			.bottom-left {
				width: 67px;
				height: 29px;
				background: #FF7200;
				opacity: 0.8;
				border-radius: 0px 0px 0px 5px;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.bottom-right {
				flex: 1;
				height: 29px;
				line-height: 29px;
				background: #FF0000;
				opacity: 0.8;
				border-radius: 0px 0px 5px 0px;
				color: #FFFFFF;
				font-size: 24rpx;
				text-align: center;
			}
		}
	}

	/deep/.tabBlock .tab__item--active{
		color: #FF7200 !important;
		font-size: 16px;
		font-family: Source Han Sans CN;
		font-weight: 500;
	}
	/deep/.tab__item-title{
		font-size: 16px;
		font-family: Source Han Sans CN;
		font-weight: 400;
	}
	/deep/.tabBlock .tab__line{
		background-color: #FF7200;
	}
	.back {
		padding-top: 80rpx;
		width: 100%;
		height: 176rpx;
		background-color: #FF7200;
		display: flex;
		align-self: center;

		.back-img {
			width: 40rpx;
			height: 40rpx;
			margin-top: 10rpx;
		}

		.back-name {
			font-size: 18px;
			line-height: 31px;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #FFFFFF;
			margin-right: 18rpx;
		}

		.search {
			position: relative;

			.search-input {
				background-color: rgba(225, 225, 225, 0.22);
				border-radius: 30rpx;
				padding-left: 60rpx;
				width: 262rpx;
				height: 64rpx;
				z-index: 99;
			}

			.search-img {
				width: 32rpx;
				height: 32rpx;
				position: absolute;
				top: 16rpx;
				left: 18rpx;
			}
		}
	}

	.banner {
		width: 100%;
		height: 334rpx;
		background-color: #BF0A0A;
		margin-bottom: 60rpx;
	}
</style>
